﻿using BCCommon;
using BCMongoEntity.StatisticsRequest;
using MongoDB.Bson;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace BCMongoData.StatisticsRequest
{
    public class StatisticsRequestMongoData: IStatisticsRequestMongoData
    {
        private MongoDBCommand<StatisticsRequestEntity> mongoCommand;
        private MongoDBCommand<BsonDocument> geoNaerCommand;

        public StatisticsRequestMongoData(IMongoDBConfiguration mongoDBConfiguration)
        {
            mongoCommand = new MongoDBCommand<StatisticsRequestEntity>(mongoDBConfiguration, "StatisticsRequest");
            geoNaerCommand = new MongoDBCommand<BsonDocument>(mongoDBConfiguration,"StatisticsRequest");
        }

        public void Append(StatisticsRequestEntity statisticsRequestEntity)
        {
           this.mongoCommand.InsertDocumentAsync(statisticsRequestEntity);
        }

        public Task<StatisticsRequestEntity> Get(int year, int month, int day, string accessApiName)
        {
            return this.mongoCommand.SelectDocumentAsync(p => p.Year == year && p.Month == month && p.Day == day && p.AccessApiName == accessApiName);
        }

        public async Task<StatisticsRequestEntity> Update(string id, UpdateDefinition<StatisticsRequestEntity> updateDefinition)
        {
            return await this.mongoCommand.UpdateDocumentAsync(d => d.Id == id, updateDefinition);
        }
        
    }
}
